package com.woniu.zsd.permission.controller;


import com.woniu.zsd.permission.Permission.Permission;
import com.woniu.zsd.commons.core.model.Result;
import com.woniu.zsd.permission.entity.AdminInfo;
import com.woniu.zsd.permission.entity.RolesResource;
import com.woniu.zsd.permission.service.IRolesResourceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2025-03-27
 */
@RestController
@RequestMapping("/roles-resource")
@Api(tags = "角色资源管理")
public class RolesResourceController {
    @Autowired
    private IRolesResourceService rolesResourceService;
    @PutMapping("/addRolesResource")
    @ApiOperation(value = "新增角色资源")
    @Permission("addRolesResource")
    public Result addRolesResource(@ApiParam(name = "rolesId", value = "角色ID")@RequestParam Integer rolesId,@ApiParam(name = "resourceId", value = "资源ID") @RequestParam Integer resourceId){
        rolesResourceService.addRolesResource(rolesId,resourceId);
        return Result.getResult().setCode(200);
    }

    @DeleteMapping("/deleteRolesResource")
    @ApiOperation(value = "删除角色资源")
    @Permission("deleteRolesResource")
    public Result deleteRolesResource(@RequestParam Integer id) {
        rolesResourceService.deleteRolesResource(id);
        return Result.getResult().setCode(200);
    }

    @PostMapping("/updateRolesResource")
    @ApiOperation(value = "修改角色资源")
    @Permission("updateRolesResource")
    public Result updateRolesResource(@RequestParam Integer id,@ApiParam(name = "rolesId", value = "角色ID")@RequestParam Integer rolesId,@ApiParam(name = "resourceId", value = "资源ID")@RequestParam Integer resourceId) {
        rolesResourceService.updateRolesResource(id,rolesId,resourceId);
        return Result.getResult().setCode(200);
    }
    @GetMapping("/selRolesResource")
    @ApiOperation(value = "查询角色资源")
    @Permission("selRolesResource")
    public Result<List<RolesResource>> selRolesResource(@RequestParam Integer rolesId) {
        List<RolesResource> rolesResource = rolesResourceService.selRolesResource(rolesId);
        return new Result<List<RolesResource>>().setData(rolesResource).setMsg("查询成功").setCode(200);
    }
    @GetMapping("/findAll")
    @ApiOperation(value = "查询所有角色资源")
    @Permission("findAll")
    public Result<List<RolesResource>> findAll() {
        List<RolesResource> rolesResourceList =rolesResourceService.findAll();
        return new Result<List<RolesResource>>().setData(rolesResourceList).setCode(200).setMsg("查询成功");
    }
}
